﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using DLL;
using System.Data;

namespace WebApplication2
{
    /// <summary>
    /// Login1 的摘要说明
    /// </summary>
    public class Login1 :IHttpHandler,System.Web.SessionState.IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            UserModel us = new UserModel();
            us.UserID = context.Request["UserPhone"];
            us.UserPwd = context.Request["UserPwd"];
            DataTable dt = UserInfoBLL.selectUser(us.UserID, us.UserPwd);
            if (dt.Rows.Count > 0)
            {
                us.UserName = dt.Rows[0]["UserName"].ToString();
                us.UserEmail = dt.Rows[0]["UserEmail"].ToString();
                us.UserImage = dt.Rows[0]["UserImage"].ToString();
                context.Session["User"] = us;
                if (context.Request["cheBox"] == "1")
                {
                    HttpCookie cookie = new HttpCookie("UserID",us.UserID);//初始化设置Cookie的名称
                    HttpCookie cookie1 = new HttpCookie("UserPwd", us.UserPwd);
                    cookie.Expires = DateTime.Now.AddDays(3);
                    cookie1.Expires = DateTime.Now.AddDays(3);
                    context.Response.Cookies.Add(cookie);
                    context.Response.Cookies.Add(cookie1);
                }
                context.Response.Write(1);
            }
            else
            {
                context.Response.Write(2);
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}